package com.github.sbb.drools.drools;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map;

/**
 * 使用map的record
 *
 * @author chensong.cs
 */
public class MapRecord implements Record {

  private Map<String, Object> mapData;

  public MapRecord() {
    mapData = new HashMap<>();
  }

  @Override
  public Object get(String fieldName) {
    return mapData.get(fieldName);
  }

  @Override
  public String getString(String fieldName) {
    Object data = mapData.get(fieldName);
    return data == null ? null : data.toString();
  }

  @Override
  public byte[] getBytes(String fieldName) {
    return (byte[]) mapData.get(fieldName);
  }

  @Override
  public long getLong(String fieldName) {
    return (long) mapData.get(fieldName);
  }

  @Override
  public double getDouble(String fieldName) {
    return (double) mapData.get(fieldName);
  }

  @Override
  public boolean getBoolean(String fieldName) {
    return (boolean) mapData.get(fieldName);
  }

  @Override
  public BigInteger getBigInteger(String fieldName) {
    return (BigInteger) mapData.get(fieldName);
  }

  @Override
  public BigDecimal getBigDecimal(String fieldName) {
    return (BigDecimal) mapData.get(fieldName);
  }

  @Override
  public Date getDate(String fieldName) {
    return (Date) mapData.get(fieldName);
  }

  @Override
  public Time getTime(String fieldName) {
    return (Time) mapData.get(fieldName);
  }

  @Override
  public Timestamp getTimestamp(String fieldName) {
    return (Timestamp) mapData.get(fieldName);
  }

  @Override
  public void set(String fieldName, Object value) {
    mapData.put(fieldName, value);
  }

  @Override
  public void setString(String fieldName, String value) {
    mapData.put(fieldName, value);
  }

  @Override
  public void setBytes(String fieldName, byte[] value) {
    mapData.put(fieldName, value);
  }

  @Override
  public void setLong(String fieldName, long value) {
    mapData.put(fieldName, value);
  }

  @Override
  public void setDouble(String fieldName, double value) {
    mapData.put(fieldName, value);
  }

  @Override
  public void setBoolean(String fieldName, boolean value) {
    mapData.put(fieldName, value);
  }

  @Override
  public void setBigInteger(String fieldName, BigInteger value) {
    mapData.put(fieldName, value);
  }

  @Override
  public void setBigDecimal(String fieldName, BigDecimal value) {
    mapData.put(fieldName, value);
  }

  @Override
  public void setDate(String fieldName, Date value) {
    mapData.put(fieldName, value);
  }

  @Override
  public void setTime(String fieldName, Time value) {
    mapData.put(fieldName, value);
  }

  @Override
  public void setTimestamp(String fieldName, Timestamp value) {
    mapData.put(fieldName, value);
  }

  @Override
  public int size() {
    return mapData.size();
  }

  @Override
  public boolean contains(String fieldName) {
    return mapData.containsKey(fieldName);
  }

}
